<template>
  <div class="proof">
    <NavHeader title="学术审稿" />
    <div class="proof-content">
      <div class="content-left">
        <LeftSider
          :id="id"
          title="审稿"
          :list="chatlist"
          @transmit="getMessage"
          @del="del"
          @clear="clear"
        />
      </div>
      <div class="content-right">
        <div v-if="typePage == 0" class="content1">
          <div class="right-con">
            <div class="upload-file">
              <div class="upload-file-title">上传文档，立即审稿：</div>
              <el-upload
                drag
                :action="action"
                :headers="headerObj"
                hit=""
                :data="uploadObjs"
                accept=".docx"
                :on-success="getChatHisList"
              >
                <img
                  class="upload-icon"
                  src="@/assets/imgs/upload-alt.png"
                  alt=""
                />
                <div class="el-upload-text">点击上传或拖拽文件到此处</div>
                <div class="el-upload-type">仅支持docx文件小于15M</div>
              </el-upload>
              <div class="el-upload-btn">提交总结</div>
            </div>
            <div class="academic-advertise">
              <div class="academic-advertise__poster">
                <img src="@/assets/imgs/academic-home-01.png" alt="" />
                <span class="academic-advertise__title">自动提取与解析</span>
                <span class="academic-advertise__tips"
                  >仅需上传文档，即可让AI全面解读您的论文，进行详细解析，精准提取要点</span
                >
              </div>
              <div class="academic-advertise__poster">
                <img src="@/assets/imgs/academic-home-02.png" alt="" />
                <span class="academic-advertise__title">智能评估</span>
                <span class="academic-advertise__tips"
                  >不再为主观性审稿意见和缺乏经验的问题而担忧！我们为您提供标准化、客观的评估，准确反馈</span
                >
              </div>
              <div class="academic-advertise__poster">
                <img src="@/assets/imgs/academic-home-03.png" alt="" />
                <span class="academic-advertise__title">专业改进建议</span>
                <span class="academic-advertise__tips"
                  >提供针对性的改进建议，助您更轻松履行审稿人职责，同时提高论文质量</span
                >
              </div>
            </div>
          </div>
        </div>
        <div v-if="typePage == 1" class="content2">
          <div v-if="repotrContent" class="text">
            <MarkDisplay :markdown="repotrContent" repotr-content-ctrl />
            <!-- <v-md-preview class="content" :text="repotrContent" /> -->
          </div>
          <div v-else>解析中</div>
          <!-- <div class="pbtn" @click="download">导出</div> -->
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import NavHeader from "@/components/NavHeader";
import LeftSider from "@/components/LeftSider";
import { fetchData } from "@/utils";
import { getChatHis, delChatHis } from "@/api/translate";
import MarkdownIt from "markdown-it";
import { saveAs } from "file-saver";
import MarkDisplay from "vue-mark-display";

export default {
  name: "Proof",
  components: {
    MarkDisplay,
    NavHeader,
    LeftSider,
  },
  data() {
    return {
      id: 0,
      cacheFilter: { type: "7" },
      headerObj: {
        authToken: localStorage.getItem("userinfo")
          ? JSON.parse(localStorage.getItem("userinfo")).authToken
          : "",
      },
      chatlist: [],
      typePage: 0,
      pagenum: 1,
      repotrContent: "",
      uploadObjs: {
        keyWords: "计算机",
      },
    };
  },
  computed: {
    action() {
      return `${process.env.VUE_APP_BASE_URL}/chat/reviewer`;
    },
  },
  mounted() {
    this.getChatHisList();
  },
  methods: {
    getChatHisList() {
      fetchData(getChatHis, {
        ...this.cacheFilter,
        pagesize: 20,
        pagenum: this.pagenum,
      },false).then((res) => {
        this.chatlist = res?.list || [];
        this.pages = res.pages;
      });
    },
    del(data) {
      fetchData(delChatHis, { id: data.id },false).then(() => {
        this.$message.success("删除成功!");
        this.pagenum = 1;
        this.getChatHisList();
        this.clear();
      });
    },
    clear() {
      if (this.id == 0) {
        this.$message.warning("当前已是新论文总结了!");
      } else {
        this.id = 0;
        this.repotrContent = "";
        this.reportTitle = "";
        this.typePage = "0";
      }
    },
    getMessage(data) {
      this.typePage = 1;
      this.repotrContent = data.backtext || '';
      this.reportTitle = data.fromtext;
      this.id = data.id;
    },
    download() {
      var md = new MarkdownIt();
      const convertedHtml = md.render(this.repotrContent);
      console.log(convertedHtml);
      const blob = new Blob([convertedHtml], {
        type: "application/vnd.ms-powerpoint;charset=utf-8",
      });
      saveAs(blob, `${this.reportTitle}.ppt`);
    },
  },
};
</script>

<style lang="less" scoped>
.proof {
  width: 100%;
  height: 100vh;
  display: flex;
  flex-direction: column;
  .proof-content {
    flex: 1;
    display: flex;
    overflow: hidden;
    .content-left {
      height: 100%;
    }
    .content-right {
      flex: 1;
      overflow: auto;
      .content1 {
        min-width: 1200px;
        padding: 50px 0 40px;
        box-sizing: border-box;
        .right-con {
          width: 1200px;
          margin: 0 auto;
          .upload-file {
            width: 1200px;
            height: 452px;
            background: #ffffff;
            box-shadow: 0 6px 16px 1px #0000000a;
            border-radius: 16px;
            opacity: 1;
            padding: 24px 40px 50px;
            box-sizing: border-box;
            .upload-icon {
              width: 60px;
              height: 60px;
              margin: 60px 0 16px;
            }
            .upload-file-title {
              height: 20px;
              font-size: 14px;
              font-weight: 400;
              color: #141414;
              line-height: 20px;
              margin-bottom: 24px;
            }
            /deep/ .el-upload-dragger {
              width: 1120px;
              height: 260px;
              background: #fafbfc;
              border-radius: 8px;
              margin-bottom: 30px;
            }
            .el-upload-text {
              font-size: 13px;
              font-weight: 400;
              color: #595959;
              line-height: 18px;
              margin-bottom: 10px;
            }
            .el-upload-type {
              font-size: 13px;
              font-weight: 400;
              color: #a1a1a1;
              line-height: 18px;
            }
            .el-upload-btn {
              width: 140px;
              height: 42px;
              line-height: 42px;
              border-radius: 8px;
              background: linear-gradient(219deg, #6468e7 0%, #8a55fe 100%);
              transition: all 0.3s ease-in-out;
              cursor: pointer;
              text-align: center;
              color: #fff;
              font-size: 14px;
              margin: 0 auto;
              &:hover {
                box-shadow: 2px 4px 10px 1px #00000029;
              }
            }
          }
          .academic-advertise {
            width: 100%;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 0 130px;
            margin-top: 60px;
            .academic-advertise__poster {
              display: flex;
              flex-direction: column;
              align-items: center;
              img {
                width: 120px;
                height: 90px;
              }
              .academic-advertise__title {
                height: 21px;
                font-size: 15px;
                font-weight: 400;
                color: #141414;
                line-height: 20px;
                margin-bottom: 16px;
                margin-top: 3px;
              }
              .academic-advertise__tips {
                font-size: 12px;
                font-weight: 400;
                color: #595959;
                line-height: 22px;
                width: 230px;
                text-align: center;
                display: inline-block;
              }
            }
          }
        }
      }
      .content2 {
        background-color: #fff;
        width: 960px;
        margin: 0 auto;
        padding: 30px 30px 80px;
        box-sizing: border-box;
        min-height: calc(100vh - 54px);
        position: relative;
        .title {
          text-align: center;
          font-size: 30px;
          font-weight: 400;
          color: #3f4654;
          line-height: 42px;
          margin-top: 130px;
        }
        .text {
          font-size: 14px;
          line-height: 28px;
          color: #141414;
          margin-top: 60px;
        }
        .pbtn {
          position: absolute;
          top: 60px;
          right: 40px;
          border: none;
          outline: none;
          width: 132px;
          height: 36px;
          line-height: 36px;
          border-radius: 6px;
          text-align: center;
          color: #fff;
          background-color: #6965ea;
          cursor: pointer;
          font-size: 13px;
        }
      }
    }
  }
}
</style>
